import React, { useEffect, useState } from 'react';
import Top from '../../components/Top/Top';
import { reqGoods } from "../../request/api"
import querystring from "querystring"
import {Link}from "react-router-dom"
import "./Cate.css"
const Cate = (props) => {
  const title = "商品分类"
  const { location: { search } } = props
  let fid = querystring.parse(search.slice(1)).id
  const [arr, setArr] = useState([])
  useEffect(() => {
    reqGoods({ fid }).then(res => {
      if (res.data.code === 200) {
        setArr(res.data.list)
      }
    })
  }, [])
  return (
    <div>
      <Top title={title}></Top>
      {
        arr.map((item) => (
          <Link className="cate_box" to="/detail" key={item.id} >
            <div>id:{item.id}</div>
            <img src={item.img} alt="" />
            <div>{item.goodsname}</div>
            <div>price:{item.price}</div>
            <div>market_price:{item.market_price}</div>
          </Link>
        ))
      }
    </div>
  );
}

export default Cate;
